package com.logindemo.servlet; /**
 * @author wzm
 * @create 2023-03-08 9:16
 */

import com.logindemo.entity.User;
import com.logindemo.service.UserSerivce;
import com.logindemo.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/serachServlet")
public class SerachServlet extends HttpServlet {
    private UserSerivce userSerivce = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //搜索

        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        String likename = request.getParameter("likename");

        User user = new User(likename);

        List<User> userList = userSerivce.selectByName(user);

        response.getWriter().write(userList.toString());

        //跳转到jsp中使用java代码把数据拿出来



    }
}
